package kadledav.adventure.game;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import kadledav.adventure.framework.builder.name.SimpleNameBuilder;

public class Example1 {
	public static String AUTO_MODE = "auto";
	
	public static void main(String[] args) throws UnsupportedEncodingException {
		SimpleNameBuilder game = buildExampleGame();
		if(args != null && args.length == 1 && AUTO_MODE.equalsIgnoreCase(args[0])){
			setAutoMode(game);
		}
		game.startGame("Ukazkova hra 1");
	}

	private static void setAutoMode(SimpleNameBuilder game) {
		String commands = "look\n" +
				"take it2\n" +
				"take it1\n" +
				"take it0\n" +
				"inventory\n" +
				"use in1\n" +
				"inventory\n" +
				"look\n" +
				"go ex0\n" +
				"look\n" +
				"go ex1\n" +
				"inventory\n" +
				"use in0 in1\n" +
				"inventory\n" +
				"drop in1\n" +
				"inventory\n" +
				"look\n" +
				"use in0 ex1\n" +
				"look\n" +
				"go ex1\n" +
				"look\n" +
				"take it0\n";
		
		try {
			InputStream testInput = new ByteArrayInputStream( commands.getBytes("UTF-8") );
			System.setIn(testInput);
			System.out.println("Spoustim automaticky rezim hry s posloupnosti prikazu:\n"+commands);					
		} catch (UnsupportedEncodingException e) {
			System.err.print("Nemohu spustit auto rezim hry");
			e.printStackTrace();
		}
	}

	private static SimpleNameBuilder buildExampleGame() {
		SimpleNameBuilder build = new SimpleNameBuilder();

		build.createLocation("lokace prvni", "hmm toto je prvni lokace");
		build.createLocation("lokace druha", "hmm toto je druha lokace");
		build.createLocation("lokace treti", "hmm toto je treti lokace");
		
		build.createStaticItem("socha", "V muzeu by byla urcite nalezite ocenena.");
		build.createItem("prazdny plamenomet", "Pekna vecicka skoda ze je bez plynu.");
		build.createItem("plyn","Sice smrdi ale mohl by se hodit.");
		build.createItem("funkcni plamenomet", "");
		build.createItem("krabice", "Copak asi tak bude v te krabici.");
		build.createItem("prazdny plyn", "Na doplneni plamenometu jsem vsechen plyn spotreboval.");
		build.createItem("plamenomet", "");
		build.createItem("drahokam","Toto je vitezny predmet");
		
		build.createConnection("lokace prvni", "lokace druha", "dvere");
		build.createConnectionWithLock("lokace druha", "lokace treti", "dreveny zateras","propaleny pruchod", "plamenomet");

		build.createActionOnObjectUseObject("plyn","prazdny plamenomet","prazdny plyn","");
		build.createActionOnObjectUseObject("prazdny plamenomet", "plyn", "plamenomet" ,"Dobry napad... doplnil jsem plamenomet.");
		build.createActionOnObject("krabice", "plyn","Koukam ze je v krabici nejaky sprej, ten se muze hodit.");
		
		build.addItemsToLoaction("lokace prvni", "krabice","prazdny plamenomet","socha");
		build.addItemsToLoaction("lokace treti","drahokam");
		
		build.initGameWithFinishItem("lokace prvni", "drahokam");
		return build;
	}
}
